package com.groupjx.api;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.groupjx.tools.JXUtils;
import com.groupjx.vo.ResultVO;

import java.util.Map;

public class BaseApi {

    /**
     * 服务端地址
     */
    protected String host = "需改成正式地址";

    /**
     * 密钥。此处需填写自己的密钥
     */
    protected String secretKey = "此处需填写自己的密钥";



    public ResultVO execute(String path, Map<String, Object> paramsMap, String authorization) {
        JXUtils.sign(paramsMap, secretKey);
        String url = StrUtil.format("{}{}", host, path);
        String body = HttpUtil.createPost(url)
                .body(JSONUtil.toJsonStr(paramsMap))
                .header("authorization", authorization)
                .execute().body();

        return JSONObject.parseObject(body, ResultVO.class);
    }


}
